package studentInfo;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AccountVerifyBean {
	private DatabaseBean account = new DatabaseBean();
	public int verify(String _username,String _password) throws SQLException {
		
		String sql = "select * from account";

		ResultSet rs=account.executeQuery(sql);
		rs.beforeFirst();
		while(rs.next())
		{
			if(rs.getString("username").equals(_username))
			{
				if(rs.getString("password").equals(_password))
				{
					return 0;//验证通过
				}
				else 
					return -2;//用户名和密码不匹配
			}
		}
		return -1;//没找到用户名，用户名不存在
	}
	
	public boolean isExist(String username){
		boolean isValid = false;
		DatabaseBean.connect();
		ResultSet rs=account.executeQuery("select * from account where username='"+username+"'");
			try {
				if(rs.next()){
					isValid = true;}
					else
						isValid = false;
			} catch (SQLException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
			return isValid;
		}

	public boolean add(String username, String password1) {
		// TODO 自动生成的方法存根
		DatabaseBean.connect();
		String sql="insert into account(username,password) values('"+username+"','"+password1+"');";
		boolean rs=account.executeUpdate(sql);
		return rs;
	}
}
